<?php

namespace StarCloud\Library\Sdk;

use Framework\DiServices\HttpClient;
use Phalcon\Di;
use StarCloud\Library\Exception;
use StarCloud\Models\Doumvip\AppCookie;

class HsFuliBot
{
    /* @var $httpClient HttpClient */
    private $httpClient;

    public function __construct($config = [])
    {
        $this->httpClient = Di::getDefault()->get('httpClient');
    }

    public function getHeader()
    {
        return [
            'x-user-id' => '66e558ca000000001d0216ca',
            'x-access-token' =>  AppCookie::getAppCookie(159),
            'user-agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36',
            'sec-ch-ua' => '"Google Chrome";v="129", "Not=A?Brand";v="8", "Chromium";v="129"',
            'cookie' =>  AppCookie::getAppCookie(171),
        ];
    }
    public function getOrders($type, $startAt, $endAt, $page, $size = 20)
    {
        $url = "https://universe.xiaohongshu.com/outer-wilds/v1/vendor-private-domain/data/items?businessType={$type}&pageNo={$page}&size={$size}&startTime={$startAt}&endTime={$endAt}";

        $response = $this->httpClient->sendGetRequest($url, [], $this->getHeader());

        $result = json_decode($response->getBody()->getContents(), true);

        if (isset($result['data']['records'])) {
            return $result['data']['records'];
        }

        return false;
    }
}